<?php

class Course_model extends CI_Model {

    protected $hr = null;

    public function __construct() {
        parent::__construct();
        $this->hr = $this->load->database("hr", TRUE);
    }

    public function wf_course($where = array(), $return = 0,$sql=null) { // หลักสูตรที่เปิด : object
        $this->hr->select('CO_RUNNO,CO_CODE,CO_TNAME,CO_CANCEL,CT_CODE');
        $this->hr->from('WF_COURSE (nolock)');
        $this->hr->where('CO_CANCEL', 'N');
        if (!empty($where)) {
            $this->hr->where($where);
        }
        $qeury = $this->hr->get();
        if(!empty($sql)){ 
           return  $this->hr->queries[0];

            }
        if ($qeury->num_rows()) {
            return ($return == 1) ? $qeury->result() : $qeury->row();
        } else {
            return array(); 
        }
    } 
    
    public function wf_course_me($where = array(), $return = 0,$sql=null) { // หลักสูตรที่เปิด : object
        $this->hr->select('pn.EM_CODE
            ,cou.CO_TNAME
            ,convert(varchar,cco.CO_SDATE,103) CO_SDATE
            ,cco.CO_SDATE as SD
            
            ');
        $this->hr->from('WF_CCOO_TRAINEE cot'); // ข้อมูลต้องมาอบรม
      //  $this->hr->from('WF_CCOO_TRAINIO cot (nolock)'); // ข้อมูลการมาอบรม
        $this->hr->join('( select EM_RUNNO,EM_CODE FROM PN_ACTIVEEMP where EM_CODE="00202929"
            AND  EO_TYPE="M") pn',
                'pn.EM_RUNNO = cot.EM_RUNNO','inner'); // พนักงาน
        $this->hr->join('WF_CCO_OPEN cco ','cot.CP_RUNNO = cco.CP_RUNNO','inner');// cco  หลักสูตรที่เปิด
        $this->hr->join('WF_COURSE cou ','cou.CO_RUNNO = cco.CO_RUNNO','inner');// cou หลักสูตร
        $this->hr->where('pn.EM_CODE','00202929');
        
        
        if (!empty($where)) {
            $this->hr->where($where);
        }
        $qeury = $this->hr->get();
        if(!empty($sql)){ 
           return  $this->hr->queries[0];

            }
        if ($qeury->num_rows()) {
            return ($return == 1) ? $qeury->result() : $qeury->row();
        } else {
            return array(); 
        }
    } 
    //PN_ACTIVEEMP
    //WF_CCOO_TRAINIO
    //wf_courseopen
    
 

}

?>